package com.example.system.web;

import com.example.common.core.Result;
import com.example.system.dto.LoginParam;
import com.example.system.service.AuthorizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Api(value = "授权API", tags = "授权API")
@RestController
@RequestMapping("/system/api")
public class AuthorizationController {
    @Resource
    private HttpServletRequest request;
    @Resource
    private AuthorizationService authorizationService;

    @ApiOperation(value = "获取图形验证码",notes = "获取图形验证码")
    @GetMapping("/captcha")
    public void captcha(@RequestParam("uuid") String uuid) throws IOException {
        authorizationService.captcha(uuid);
    }

    @ApiOperation(value = "登录",notes = "登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginParam loginParam){
        return authorizationService.login(loginParam);
    }


    @ApiOperation(value = "获取当前登录管理员",notes = "获取当前登录管理员")
    @PostMapping("/authorization")
    public Result authorization(){
        String token =request.getHeader("token");
        return authorizationService.authorization(token);
    }

    @ApiOperation(value = "退出",notes = "退出")
    @GetMapping("/logout")
    public Result logout(){
        String token =request.getHeader("token");
        return authorizationService.logout(token);
    }

}
